<!doctype html>
<html class="theme-next use-motion theme-next-mist">
<head>
  
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

  <meta name="google-site-verification" content="K8DCBviaoTBKVs28YBB7IBIbospQ9RVlgSh81RYMUhY" />


  <meta name="baidu-site-verification" content="tXr3ZTm3Hx" />



  <link rel="stylesheet" type="text/css" href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5"/>


<link rel="stylesheet" type="text/css" href="/css/main.css?v=0.4.5.1"/>

  <meta name="description" content="xgfe's blog. 鲜果前端的技术博客，鲜果前端研发部官方博客。前端基础技术研究：html, html5, javascript, css, css3；前端框架研究：angularJs, react, react native." />


  <meta name="keywords" content="iOS," />


  <link rel="alternate" target="_blank" href="/atom.xml" title="xgfe" type="application/atom+xml" />


  <link rel="shorticon icon" type="image/x-icon" href="http://p0.meituan.net/xgfe/2db359f56ce13be30dedef160e0e57ce16958.ico?v=0.4.5.1" />

<meta name="description" content="本文主要分析了富文本常用的属性设置，平时工作过程经常遇到一些有特殊需求的label、UITextField、UITextView。一般情况下，大家都喜欢直接用多个label来实现其不同的属性，很多人忽略了label本身的富文本属性。本文针对富文本进行了详细的介绍。">
<meta name="keywords" content="iOS">
<meta property="og:type" content="article">
<meta property="og:title" content="关于富文本AttributedString的使用总结">
<meta property="og:url" content="http://xgfe.github.io/2017/09/22/Sudaxi/attributeStr1/index.html">
<meta property="og:site_name" content="xgfe">
<meta property="og:description" content="本文主要分析了富文本常用的属性设置，平时工作过程经常遇到一些有特殊需求的label、UITextField、UITextView。一般情况下，大家都喜欢直接用多个label来实现其不同的属性，很多人忽略了label本身的富文本属性。本文针对富文本进行了详细的介绍。">
<meta property="og:image" content="http://p0.meituan.net/xgfe/8ac5ef6b34677319cfc020c8a1406681105850.jpg">
<meta property="og:image" content="http://p0.meituan.net/xgfe/c2aebeaf980a1a784389fa2c4afa2efa113929.jpg">
<meta property="og:image" content="http://p1.meituan.net/xgfe/9da9d0eeed5b545b73b8e7d14e2b3afe99240.jpg">
<meta property="og:image" content="http://p0.meituan.net/xgfe/dccd36a6ac1a8845cbad513316355332110431.jpg">
<meta property="og:updated_time" content="2017-10-16T10:03:20.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="关于富文本AttributedString的使用总结">
<meta name="twitter:description" content="本文主要分析了富文本常用的属性设置，平时工作过程经常遇到一些有特殊需求的label、UITextField、UITextView。一般情况下，大家都喜欢直接用多个label来实现其不同的属性，很多人忽略了label本身的富文本属性。本文针对富文本进行了详细的介绍。">
<meta name="twitter:image" content="http://p0.meituan.net/xgfe/8ac5ef6b34677319cfc020c8a1406681105850.jpg">


<script type="text/javascript" id="hexo.configuration">
  var CONFIG = {
    scheme: 'Mist',
    sidebar: 'post'
  };
</script>

  <title> 关于富文本AttributedString的使用总结 | xgfe </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
  <div style="position: fixed; top: -9999px; left: -9999px;">
    <img src="http://p0.meituan.net/xgfe/082a9624ba5ae8602150a2d43968463e49348.png" alt="xgfe"/>
  </div>
  <!--[if lte IE 8]>
  <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;margin:0 auto;'>
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
      <img src="http://7u2nvr.com1.z0.glb.clouddn.com/picouterie.jpg" border="0" height="42" width="820"
           alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today or use other browser ,like chrome firefox safari."
           style='margin-left:auto;margin-right:auto;display: block;'/>
    </a>
  </div>
<![endif]-->
  

  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?3601d4483819a5ab6ddabb0b6422a328";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>



  <div class="container one-column page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><h1 class="site-meta">
  <span class="logo-line-before"><i></i></span>
  <a href="/" class="brand" rel="start">
      <span class="logo">
        <i class="icon-next-logo"></i>
      </span>
      <span class="site-title">xgfe</span>
  </a>
  <span class="logo-line-after"><i></i></span>
</h1>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  
  

  
    <ul id="menu" class="menu menu-left">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon icon-next-home"></i> <br />
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            <i class="menu-item-icon icon-next-archives"></i> <br />
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            <i class="menu-item-icon icon-next-tags"></i> <br />
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-join">
          <a href="/join" rel="section">
            <i class="menu-item-icon icon-next-join"></i> <br />
            加入我们
          </a>
        </li>
      
      <!-- slide-links added by felix -->
      <li class="menu-item menu-item-slides" style="opacity: 1; transform: translateY(0px);">
        <a href="http://xgfe.github.io/Basics/" target="_blank" rel="section">
          <i class="menu-item-icon icon-next-slides"></i> <br>
          Basics
        </a>
      </li>
      <li class="menu-item menu-item-slides" style="opacity: 1; transform: translateY(0px);">
        <a href="https://slides.com/xgfe" target="_blank" rel="section">
          <i class="menu-item-icon icon-next-slides"></i> <br>
          Slides
        </a>
      </li>

      
      
    </ul>
  

  
    <div class="site-search">
      

    </div>
  

    <div class="site-search">
      <form class="site-search-form" id="gg-form" action="https://www.google.com/webhp" >
        <input type="text" name="q" id="gg-search-input" class="menu-search-input">
      </form>
    </div>
</nav>
 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div id="content" class="content"> 

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">

      
      
        <h1 class="post-title" itemprop="name headline">
          
          
            
              关于富文本AttributedString的使用总结
            
          
        </h1>
      

      <div class="post-meta">
        <span class="post-time">
          发表于
          <time itemprop="dateCreated" datetime="2017-09-22T16:00:00+08:00" content="2017-09-22">
            2017-09-22
          </time>
        </span>

        
          <span class="post-category" >
            &nbsp; | &nbsp; 作者
            
              <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                <a href="/categories/Sudaxi/" itemprop="url" rel="index">
                  <span itemprop="name">Sudaxi</span>
                </a>
              </span>

              
              

            
          </span>
        

        
          
        

        <!-- tags 挪动位置 -->
        
          <span class="post-tags">
            &nbsp; | &nbsp;
            
              <a href="/tags/iOS/" rel="tag"><i class="icon-next-tags"></i>iOS</a>
            
          </span>
        
      </div>
    </header>

    <div class="post-body">

      
      

      
        <span itemprop="articleBody"><p>本文主要分析了富文本常用的属性设置，平时工作过程经常遇到一些有特殊需求的label、UITextField、UITextView。一般情况下，大家都喜欢直接用多个label来实现其不同的属性，很多人忽略了label本身的富文本属性。本文针对富文本进行了详细的介绍。<br><a id="more"></a></p>
<p>首先先大概了解一下NSAttributedString 的21个属性。<br>常见的属性大概如下：<br><img src="http://p0.meituan.net/xgfe/8ac5ef6b34677319cfc020c8a1406681105850.jpg" width="600" height="600" alt="常见属性"></p>
<p>API: Character Attributes , NSAttributedString 共有21个属性</p>
<pre><code>1. NSFontAttributeName -&gt;设置字体属性，默认值：字体：Helvetica(Neue) 字号：12
2. NSParagraphStyleAttributeName -&gt;设置文本段落排版格式，取值为 NSParagraphStyle 对象
3. NSForegroundColorAttributeName -&gt;设置字体颜色，取值为 UIColor对象，默认值为黑色
4. NSBackgroundColorAttributeName -&gt;设置字体所在区域背景颜色，取值为 UIColor对象，默认值为nil, 透明色
5. NSLigatureAttributeName -&gt;设置连体属性，取值为NSNumber 对象(整数)，0 表示没有连体字符，1 表示使用默认的连体字符
6. NSKernAttributeName -&gt;设置字符间距，取值为 NSNumber 对象（整数），正值间距加宽，负值间距变窄
7. NSStrikethroughStyleAttributeName -&gt;设置删除线，取值为 NSNumber 对象（整数）
8. NSStrikethroughColorAttributeName -&gt;设置删除线颜色，取值为 UIColor 对象，默认值为黑色
9. NSUnderlineStyleAttributeName -&gt;设置下划线，取值为 NSNumber 对象（整数），枚举常量 NSUnderlineStyle中的值，与删除线类似
10. NSUnderlineColorAttributeName -&gt;设置下划线颜色，取值为 UIColor 对象，默认值为黑色
11. NSStrokeWidthAttributeName -&gt;设置笔画宽度(粗细)，取值为 NSNumber 对象（整数），负值填充效果，正值中空效果
12. NSStrokeColorAttributeName -&gt;填充部分颜色，不是字体颜色，取值为 UIColor 对象
13. NSShadowAttributeName -&gt;设置阴影属性，取值为 NSShadow 对象
14. NSTextEffectAttributeName -&gt;设置文本特殊效果，取值为 NSString 对象，目前只有图版印刷效果可用
15. NSBaselineOffsetAttributeName -&gt;设置基线偏移值，取值为 NSNumber （float）,正值上偏，负值下偏
16. NSObliquenessAttributeName -&gt;设置字形倾斜度，取值为 NSNumber （float）,正值右倾，负值左倾
17. NSExpansionAttributeName -&gt;设置文本横向拉伸属性，取值为 NSNumber （float）,正值横向拉伸文本，负值横向压缩文本
18. NSWritingDirectionAttributeName -&gt;设置文字书写方向，从左向右书写或者从右向左书写
19. NSVerticalGlyphFormAttributeName -&gt;设置文字排版方向，取值为 NSNumber 对象(整数)，0 表示横排文本，1 表示竖排文本
20. NSLinkAttributeName -&gt;设置链接属性，点击后调用浏览器打开指定URL地址
21.NSAttachmentAttributeName -&gt;设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排
</code></pre><p>下面分别详细介绍整段文字不同属性的两种使用方式：</p>
<p>1、对一整段文字进行初始化，分范围（range主要是NSMakeRange(NSUInteger loc, NSUInteger len)）下标和长度进行属性化。实现不同的文字样式，再进行控件赋值。</p>
<pre><code>//其中\n可以达到分行的效果
NSString *str = @&quot;鲁班七号\n啦哈哈哈哈，不得了了。\n有人需要技术支持吗？\n鲁班大师，智商二百五，膜拜，极度膜拜。\n正在思考，如何攻克地心引力。\n请你们绕行，见识新发明的威力。\n不得不承认，有时候肌肉比头脑管用。\n检测了对面的智商，嘿嘿嘿，看来无法发挥全部实力啦。\n漏漏漏漏漏漏油啦。\n看，天上的飞机。\n相信科学。\n刮风了，吓到了。\n我想静～静～～&quot;;
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:str];
//改变某个范围的文字颜色
[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor magentaColor] range:NSMakeRange(16, 10)];
//设置特殊字体
[attributedStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20] range:NSMakeRange(27, 4)];

[attributedStr addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],
                               NSUnderlineStyleAttributeName:@1,
                               NSUnderlineColorAttributeName:[UIColor redColor]
                               } range:NSMakeRange(32, 5)];

[attributedStr addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:30],
                               NSForegroundColorAttributeName:[UIColor brownColor],
                               NSBackgroundColorAttributeName:[UIColor yellowColor]
                               } range:NSMakeRange(0, 4)];
//给控件赋值
self.showLa.attributedText = attributedStr;
</code></pre><p> 运行效果如下：<br> <img src="http://p0.meituan.net/xgfe/c2aebeaf980a1a784389fa2c4afa2efa113929.jpg" width="300" height="300" alt=""></p>
<p> 2、整段文字，根据不同的需求，拆分成n个string。创建字典，将每个string的属性初始化。然后通过拼接string将文字串起来。再给控件的赋值</p>
<pre><code> NSMutableAttributedString *muAttributedStr = [[NSMutableAttributedString alloc] init];
 NSString *titleStr = @&quot;王昭君。\n&quot;;
 NSDictionary *titleDict = @{
                             NSFontAttributeName:[UIFont boldSystemFontOfSize:30],
                             NSForegroundColorAttributeName:[UIColor brownColor],
                             NSBackgroundColorAttributeName:[UIColor yellowColor]
                             };
 NSAttributedString *attStr = [[NSAttributedString alloc] initWithString:titleStr attributes:titleDict];
 [muAttributedStr appendAttributedString:attStr];

 NSShadow *shadow = [[NSShadow alloc] init];
 shadow.shadowColor = [UIColor purpleColor];
 shadow.shadowOffset = CGSizeMake(5, 5);
 shadow.shadowBlurRadius = 3.0; 
NSString *str1 = @&quot;凛冬已至，故乡的梅花开了吗。\n心已经融化。\n身躯已然冰封，灵魂仍旧火热。\n寒梅，无处不在。\n&quot;;
NSDictionary *dict1 = @{
                         NSKernAttributeName:@5,//字符间距
                         NSShadowAttributeName:shadow,//阴影
                         NSStrikethroughStyleAttributeName:@2,
                         NSStrikethroughColorAttributeName:[UIColor redColor]
                         };
 NSAttributedString *attStr1 = [[NSAttributedString alloc] initWithString:str1 attributes:dict1];
 [muAttributedStr appendAttributedString:attStr1];


 NSString *str2 = @&quot;凛寒梅，无处不在。\n替你们消消火。\n&quot;;
 NSDictionary *dict2 = @{
                         NSKernAttributeName:@5,//字符间距
                         NSShadowAttributeName:shadow,//阴影
                         NSStrikethroughStyleAttributeName:@2,
                         NSStrikethroughColorAttributeName:[UIColor redColor]
                         };
 NSAttributedString *attStr2 = [[NSAttributedString alloc] initWithString:str2 attributes:dict2];
 [muAttributedStr appendAttributedString:attStr2];

 NSString *str3 = @&quot;百梅落下之日，归去故里之时。\n&quot;;
 NSDictionary *dict3 = @{
                         NSBaselineOffsetAttributeName:@5,
                         NSUnderlineStyleAttributeName:@1,
                         NSUnderlineColorAttributeName:[UIColor redColor],
                         NSObliquenessAttributeName:@1
                         };
 NSAttributedString *attStr3 = [[NSAttributedString alloc] initWithString:str3 attributes:dict3];
 [muAttributedStr appendAttributedString:attStr3];

 NSString *str31 = @&quot;美貌是种罪孽，暴雪也无法掩埋。\n&quot;;
 NSDictionary *dict31 = @{
                         NSBaselineOffsetAttributeName:@2,
                         NSUnderlineStyleAttributeName:@3,
                         NSUnderlineColorAttributeName:[UIColor yellowColor],
                         NSObliquenessAttributeName:@0
                         };
 NSAttributedString *attStr31 = [[NSAttributedString alloc] initWithString:str31 attributes:dict31];
 [muAttributedStr appendAttributedString:attStr31];

 NSString *str32 = @&quot;看见了.....故乡的.......春天。\n&quot;;
 NSDictionary *dict32 = @{
                          NSBaselineOffsetAttributeName:@24,
                          NSUnderlineStyleAttributeName:@2,
                          NSUnderlineColorAttributeName:[UIColor greenColor],
                          NSObliquenessAttributeName:@(-1),
                          NSExpansionAttributeName:@(-0.5)
                          };
 NSAttributedString *attStr32 = [[NSAttributedString alloc] initWithString:str32 attributes:dict32];
 [muAttributedStr appendAttributedString:attStr32];
</code></pre><p>其中需要注意的是：<br>NSStrikethroughStyleAttributeName（删除线）、NSUnderlineStyleAttributeName的value（下划线）: 1~7单线,依次加粗  9~15:双线,依次加粗<br>NSObliquenessAttributeName（倾斜）：正值右倾,负值左倾<br> 运行效果如下：<br> <img src="http://p1.meituan.net/xgfe/9da9d0eeed5b545b73b8e7d14e2b3afe99240.jpg" width="300" height="300" alt=""></p>
<p>图文混排的使用：<br>一、将图片和文字分别初始化成不同的NSAttributedString，然后拼接到NSMutableAttributedString，赋值到控件上。</p>
<pre><code>NSString *str1= @&quot;刻骨铭心~霸王！明媚如风，轻盈似箭！啊~已经放弃了做个淑女~&quot;;
NSString *str2= @&quot;净化森林，净化污秽，净化心灵，净化自己。风会带走你曾经存在过的证明。&quot;;

NSMutableAttributedString *muAttributedStr = [[NSMutableAttributedString alloc] init];

NSAttributedString *attStr = [[NSAttributedString alloc] initWithString:str1 attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],
                                                                                          NSForegroundColorAttributeName:[UIColor magentaColor]
                                                                                          }];
NSTextAttachment *attachment = [[NSTextAttachment alloc]init];
attachment.image = [UIImage imageNamed:@&quot;yujiphoto&quot;];
attachment.bounds = CGRectMake(0, 0, 110, 70);

NSAttributedString *attStr1 = [NSAttributedString attributedStringWithAttachment:attachment];

NSAttributedString *attStr2= [[NSAttributedString alloc] initWithString:str2 attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],
                                                                                          NSBackgroundColorAttributeName:[UIColor clearColor]}];

 [muAttributedStr appendAttributedString:attStr];
 [muAttributedStr appendAttributedString:attStr1];
 [muAttributedStr appendAttributedString:attStr2];
</code></pre><p>二、使用insertAttributedString将图片插入到文字中。</p>
<pre><code>NSString *str3 = @&quot;一点疼痛能让偷窥者牢记我的魅力！不为所爱之人哭泣，只因从未离去。想和风比赛脚力吗？弱小，并非服从恐惧的理由！&quot;;
NSMutableAttributedString *mustr = [[NSMutableAttributedString alloc] initWithString:str3];
NSTextAttachment *attachMent1 = [[NSTextAttachment alloc] init];
attachMent1.image = [UIImage imageNamed:@&quot;photo23&quot;];
attachMent1.bounds = CGRectMake(0, 0, 110, 70);
[mustr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],
                         NSForegroundColorAttributeName:[UIColor greenColor]
                         } range:NSMakeRange(0, 8)];
NSAttributedString *att = [NSAttributedString attributedStringWithAttachment:attachMent1];
[mustr insertAttributedString:att atIndex:6];
[muAttributedStr appendAttributedString:mustr];
使用
self.showLa.attributedText = muAttributedStr;
</code></pre><p> 运行效果如下：<br>  <img src="http://p0.meituan.net/xgfe/dccd36a6ac1a8845cbad513316355332110431.jpg" width="300" height="300" alt=""></p>
<p>介绍了富文本的常用属性，并且介绍了一些常用的场景后，安利一个富文本第三方库—YYText（github的地址—<a href="https://github.com/ibireme/YYText）。详细的使用可以参考一下github上面的介绍。" target="_blank" rel="external">https://github.com/ibireme/YYText）。详细的使用可以参考一下github上面的介绍。</a></p>
</span>
      
    </div>

    <footer class="post-footer">

      
        <div class="post-nav">
          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/18/lulutia/IntersectionObserver/" rel="prev">基于IntersectionObserver的曝光统计测试</a>
            
          </div>

          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/20/Young/DOM-size/" rel="next">由一个表格需求引发的blog-DOM中的尺寸属性</a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>

 </div>

        

        
          <div class="comments" id="comments">
            <div id="SOHUCS" sid="" ></div>
          </div>
        
      </div>

      
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <a href="https://github.com/xgfe" target="_blank"><img class="site-author-image" src="http://p0.meituan.net/xgfe/082a9624ba5ae8602150a2d43968463e49348.png" alt="xgfe" itemprop="image"/></a>
          <p class="site-author-name" itemprop="name">xgfe</p>
        </div>
        <p class="site-description motion-element" itemprop="description">xgfe's blog. 鲜果前端的技术博客，鲜果前端研发部官方博客。前端基础技术研究：html, html5, javascript, css, css3；前端框架研究：angularJs, react, react native.</p>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">89</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          <div class="site-state-item site-state-categories">
            
              <span class="site-state-item-count">37</span>
              <span class="site-state-item-name">作者</span>
              
          </div>

          <div class="site-state-item site-state-tags">
            <a href="/tags">
              <span class="site-state-item-count">131</span>
              <span class="site-state-item-name">标签</span>
              </a>
          </div>

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" target="_blank" rel="alternate">
              <i class="menu-item-icon icon-next-feed"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/xgfe" target="_blank">GitHub</a>
              </span>
            
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      
        <section class="post-toc-wrap sidebar-panel-active">
          <div class="post-toc-indicator-top post-toc-indicator"></div>
          <div class="post-toc">
            
            
              <p class="post-toc-empty">此文章未包含目录</p>
            
          </div>
          <div class="post-toc-indicator-bottom post-toc-indicator"></div>
        </section>
      

    </div>
  </aside>


    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner"> <div class="copyright" >
  
  &copy; &nbsp; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="icon-next-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xgfe</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" target="_blank" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


 </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  
  
    <script type="text/javascript"> 
(function(){ 
var appid = 'cysWiXvkm'; 
var conf = 'prod_fc970dbe85103c7a79b2c4f3dc7fb190'; 
var width = window.innerWidth || document.documentElement.clientWidth; 
if (width < 960) { 
window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("http://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); </script>
    

  


  
  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>
  <script type="text/javascript" src="/js/fancy-box.js?v=0.4.5.1"></script>


  <script type="text/javascript" src="/js/helpers.js?v=0.4.5.1"></script>
  

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/js/motion_global.js?v=0.4.5.1" id="motion.global"></script>




  <script type="text/javascript" src="/js/nav-toggle.js?v=0.4.5.1"></script>
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  
<script type="text/javascript" src="/js/bootstrap.scrollspy.js?v=0.4.5.1" id="bootstrap.scrollspy.custom"></script>


<script type="text/javascript" id="sidebar.toc.highlight">
  $(document).ready(function () {
    var tocSelector = '.post-toc';
    var $tocSelector = $(tocSelector);
    var activeCurrentSelector = '.active-current';

    $tocSelector
      .on('activate.bs.scrollspy', function () {
        var $currentActiveElement = $(tocSelector + ' .active').last();

        removeCurrentActiveClass();
        $currentActiveElement.addClass('active-current');

        $tocSelector[0].scrollTop = $currentActiveElement.position().top;
      })
      .on('clear.bs.scrollspy', function () {
        removeCurrentActiveClass();
      });

    function removeCurrentActiveClass () {
      $(tocSelector + ' ' + activeCurrentSelector)
        .removeClass(activeCurrentSelector.substring(1));
    }

    function processTOC () {
      getTOCMaxHeight();
      toggleTOCOverflowIndicators();
    }

    function getTOCMaxHeight () {
      var height = $('.sidebar').height() -
                   $tocSelector.position().top -
                   $('.post-toc-indicator-bottom').height();

      $tocSelector.css('height', height);

      return height;
    }

    function toggleTOCOverflowIndicators () {
      tocOverflowIndicator(
        '.post-toc-indicator-top',
        $tocSelector.scrollTop() > 0 ? 'show' : 'hide'
      );

      tocOverflowIndicator(
        '.post-toc-indicator-bottom',
        $tocSelector.scrollTop() >= $tocSelector.find('ol').height() - $tocSelector.height() ? 'hide' : 'show'
      )
    }

    $(document).on('sidebar.motion.complete', function () {
      processTOC();
    });

    $('body').scrollspy({ target: tocSelector });
    $(window).on('resize', function () {
      if ( $('.sidebar').hasClass('sidebar-active') ) {
        processTOC();
      }
    });

    onScroll($tocSelector);

    function onScroll (element) {
      element.on('mousewheel DOMMouseScroll', function (event) {
          var oe = event.originalEvent;
          var delta = oe.wheelDelta || -oe.detail;

          this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
          event.preventDefault();

          toggleTOCOverflowIndicators();
      });
    }

    function tocOverflowIndicator (indicator, action) {
      var $indicator = $(indicator);
      var opacity = action === 'show' ? 0.4 : 0;
      $indicator.velocity ?
        $indicator.velocity('stop').velocity({
          opacity: opacity
        }, { duration: 100 }) :
        $indicator.stop().animate({
          opacity: opacity
        }, 100);
    }

  });
</script>

<script type="text/javascript" id="sidebar.nav">
  $(document).ready(function () {
    var html = $('html');
    var TAB_ANIMATE_DURATION = 200;
    var hasVelocity = $.isFunction(html.velocity);

    $('.sidebar-nav li').on('click', function () {
      var item = $(this);
      var activeTabClassName = 'sidebar-nav-active';
      var activePanelClassName = 'sidebar-panel-active';
      if (item.hasClass(activeTabClassName)) {
        return;
      }

      var currentTarget = $('.' + activePanelClassName);
      var target = $('.' + item.data('target'));

      hasVelocity ?
        currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
          target
            .velocity('stop')
            .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
            .addClass(activePanelClassName);
        }) :
        currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
          currentTarget.hide();
          target
            .stop()
            .css({'opacity': 0, 'display': 'block'})
            .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
              currentTarget.removeClass(activePanelClassName);
              target.addClass(activePanelClassName);
            });
        });

      item.siblings().removeClass(activeTabClassName);
      item.addClass(activeTabClassName);
    });

    $('.post-toc a').on('click', function (e) {
      e.preventDefault();
      var targetSelector = escapeSelector(this.getAttribute('href'));
      var offset = $(targetSelector).offset().top;
      hasVelocity ?
        html.velocity('stop').velocity('scroll', {
          offset: offset  + 'px',
          mobileHA: false
        }) :
        $('html, body').stop().animate({
          scrollTop: offset
        }, 500);
    });

    // Expand sidebar on post detail page by default, when post has a toc.
    var $tocContent = $('.post-toc-content');
    if (isDesktop() && CONFIG.sidebar === 'post') {
      if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
        displaySidebar();
      }
    }
  });
</script>



  <script type="text/javascript">
    $(document).ready(function () {
      if (CONFIG.sidebar === 'always') {
        displaySidebar();
      }
      if (isMobile()) {
        FastClick.attach(document.body);
      }
    });
  </script>

  

  
  

  
  <script type="text/javascript" src="/js/lazyload.js"></script>
  <script type="text/javascript">
    $(function () {
      $("#posts").find('img').lazyload({
        placeholder: "/images/loading.gif",
        effect: "fadeIn"
      });
    });
  </script>

  <!-- google search, added by felix -->
  <script>
      $('#gg-form').on('submit', function(e) {
        var keyword = $.trim($(this).find('#gg-search-input').val());
        if (keyword) {
          location.href = 'https://www.google.com.hk/?gfe_rd=cr&ei=hXw8VpjtHuLC8AeSuIjQAg&gws_rd=ssl#safe=strict&q='+encodeURIComponent(keyword)+'+site:xgfe.github.io';
        }
        return false;
      });
  </script>
  <!-- baidu 站长自动推送 -->
  <script>
  (function(){
      var bp = document.createElement('script');
      bp.src = '//push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>
</body>
</html>
